package interview.huawei.myself.machine_test;

import java.util.Scanner;

public class Main2_1 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String str1 = in.nextLine();
        String str2 = in.nextLine();
//        String str1 = "ace";
//        String str2 = "abcde";
        int p1 = 0, p2 = 0;
        for (p2 = 0; p2 < str2.length() && p1 < str1.length(); p2++) {
            if (str2.charAt(p2) == str1.charAt(p1)) {
                p1++;
            }
        }
        System.out.println(p1 == str1.length() ? p2 - 1 : -1);
    }
}